<%-- 
    Document   : listVisits
    Created on : 17.11.2013, 19:40:19
    Author     : palo
--%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<f:message var="nadpis" key="top.listVisits"/>

<s:layout-render name="/mainLayout.jsp" nadpis="${nadpis}">
    <s:layout-component name="body">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
        <script type="text/javascript">
            //<![CDATA[
            $(document).ready(function() {
                $('.toggle').hide();
                var global;
                $('.toggler').click(function() {
                    var target = this.id + '_content';
                    if (global != target) {
                        $('#' + global).hide();
                    }


                    // Use ID-selectors to toggle a single element.
                    $('#' + target).toggle();
                    global = this.id + '_content';

                });

            });
            //]]></script>

        <s:useActionBean beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean" var="actionBean"/>    
        <s:useActionBean beanclass="cz.muni.fi.pa165.mushroom.website.web.ForestActionBean" var="forestActionBean"/>

        <br />
        <shiro:hasRole name="ROLE_USER">
        <s:form beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean">
           
            <table>
                <tr>
                    <th><s:label for="b1" name="filter.visitByForest"/></th>
                    
                    <td>   
                    <td>
                        <s:select id="b1" name="forestDto.id">
                            <c:forEach items="${forestActionBean.forest}" var="forestDto">
                                <s:option value="${forestDto.id}">${forestDto.name}</s:option>
                            </c:forEach> 
                        </s:select>
                    </td>
                    <td><s:submit name="showVisitsByForest"><f:message key="visit.filter"/></s:submit></td>
                    </tr>
                </table>
        </s:form>

        <s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean" event="showVisits"  class="cancelFilter">
            <f:message key="cancel.filter"/>
        </s:link>  
            
        </shiro:hasRole>    




        <h2><f:message key="top.listVisits"/> </h2>
         <c:choose>
            <c:when test="${empty actionBean.visitsTest}">
                <p><f:message key="visit.list.empty"/></p>
            </c:when>
            <c:otherwise>
        
        <table class="basic">
            <tr>
                <th><f:message key="listVisits.gatherer"/></th>
                <th><f:message key="listVisits.forest"/> </th>
                <th><f:message key="listVisits.info"/></th>
                <th><f:message key="listVisits.mushrooms"/></th>
            </tr>

            <c:forEach items="${actionBean.visitsTest}" var="visitDto" varStatus="status">   
                <tr>
                    <td><a class="toggler" id="Gatherer_${status.count}"><c:out value="${visitDto.gathererDto.firstName} ${visitDto.gathererDto.lastName}"/></a></td>
                    <td><a class="toggler" id="Forest_${status.count}"><c:out value="${visitDto.forestDto.name}"/></a></td>
                    <td><c:out value="${visitDto.info}"/></td>
                    <td>
                        <c:forEach items="${visitDto.mushrooms}" var="mushroom" varStatus="loopStatus" >
                            <c:out value="${mushroom.name}"/>
                            <c:if test="${!loopStatus.last}">,</c:if>

                        </c:forEach>    
                    </td>


                <tr class="toggle" id="Gatherer_${status.count}_content">

                    <td colspan="4">
                        <f:message key="listVisits.gathererMore"/>:<strong><c:out value="${visitDto.gathererDto.firstName}"/></strong><br /><br />
                <u><f:message key="gatherer.username"/></u>: <c:out value="${visitDto.gathererDto.username}"/> <br />
                <u><f:message key="gatherer.firstName"/></u>: <c:out value="${visitDto.gathererDto.firstName}"/><br />
                <u><f:message key="gatherer.lastName"/></u>: <c:out value="${visitDto.gathererDto.lastName}"/><br />
                <u><f:message key="gatherer.info"/></u>: <c:out value="${visitDto.gathererDto.info}"/><br />
            </td>
        </tr>

        <tr class="toggle" id="Forest_${status.count}_content">

            <td colspan="4">
                <f:message key="listVisits.forestMore"/>:<strong><c:out value="${visitDto.forestDto.name}"/></strong><br /><br />
        <u><f:message key="showForest.name"/></u>: <c:out value="${visitDto.forestDto.name}"/> <br />
        <u><f:message key="showForest.description"/></u>: <c:out value="${visitDto.forestDto.description}"/><br />

    </td>
</tr>



</c:forEach> 

</table>
            </c:otherwise>
         </c:choose>
</s:layout-component>
</s:layout-render>
<div class="toggle" id="${visitDto.gathererDto.firstName}_content">
    <tr>
        <td></td>
    </tr>
</div>